/*
 * Decompiled with CFR 0.150.
 * 
 * Could not load the following classes:
 *  cn.hutool.core.util.ObjectUtil
 *  de.felixroske.jfxsupport.FXMLController
 *  javafx.event.EventHandler
 *  javafx.fxml.FXML
 *  javafx.fxml.Initializable
 *  javafx.scene.control.TextField
 *  javafx.scene.input.KeyCode
 *  javafx.scene.input.KeyEvent
 *  javafx.scene.layout.AnchorPane
 *  javafx.stage.Stage
 *  org.springframework.beans.factory.annotation.Autowired
 */
package com.gys.controller.rechargecard;

import cn.hutool.core.util.ObjectUtil;
import com.gys.common.util.SpringUtil;
import com.gys.controller.BaseController;
import com.gys.controller.dataManger.ControllerManger;
import com.gys.controller.rechargecard.RechargePayController;
import com.gys.view.rechargecard.PayView;
import de.felixroske.jfxsupport.FXMLController;
import java.net.URL;
import java.util.ResourceBundle;
import java.util.Timer;
import java.util.TimerTask;
import javafx.event.EventHandler;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.TextField;
import javafx.scene.input.KeyCode;
import javafx.scene.input.KeyEvent;
import javafx.scene.layout.AnchorPane;
import javafx.stage.Stage;
import org.springframework.beans.factory.annotation.Autowired;

@FXMLController
public class RechargeScanPayController
extends BaseController
implements Initializable {
    @FXML
    private AnchorPane pane;
    @FXML
    public TextField payCode;
    @Autowired
    private RechargePayController payController;

    public void initialize(URL location, ResourceBundle resources) {
        ControllerManger.controllerMap.put(this.getClass().getSimpleName(), this);
        this.init();
    }

    @Override
    public void init() {
        if (ObjectUtil.isEmpty(this.pane)) {
            return;
        }
        new Timer().schedule(new TimerTask(){

            @Override
            public void run() {
                PayView view = SpringUtil.getBean(PayView.class);
                Stage stage = (Stage)view.getView().getScene().getWindow();
                stage.getScene().setOnKeyReleased((EventHandler)new EventHandler<KeyEvent>(){

                    public void handle(KeyEvent event) {
                        if (event.getCode() == KeyCode.ENTER) {
                            RechargeScanPayController.this.pay();
                            return;
                        }
                    }
                });
            }
        }, 1000L);
    }

    @FXML
    private void pay() {
        this.payController.scanPay(this.payCode.getText());
        this.payCode.setText("");
        this.pane.getScene().getWindow().hide();
    }
}

